package P11;

import org.junit.Test;

/**
 * @Author DJ同学
 * @Date 2021/2/24 19:00
 * @Version 1.0
 * @Name 盛最多水的容器
 * @Problem https://leetcode-cn.com/problems/container-with-most-water/
 * @Idea 双指针
 */
public class Solution {
    @Test
    public void test(){
        int i = maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7});
        System.out.println(i);
    }

    public int maxArea(int[] height) {
        int i = 0;
        int j = height.length-1;
        int res = 0;
        while(i!=j){
            res = Math.max(res,(j-i)*Math.min(height[i],height[j]));
            if(height[i]>height[j]){
                j--;
            }else{
                i++;
            }
           System.out.println(res);
        }
        return res;
    }
}
